<!DOCTYPE html>
<html lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  
  <title itemprop="name">SpringCloud Alibaba | MY HOUSE!</title>
  
    <link rel="shortcut icon" href="/img/favicon.ico">
  
  <meta http-equiv="x-dns-prefetch-control" content="on">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto+SerifMerriweather|Merriweather+Sans|Source+Code+Pro|Ubuntu:400,700|Noto+Serif+SC" media="all">
  <link rel="dns-prefetch" href="//cdn.jsdelivr.net">
  <link rel="stylesheet" id="saukra_css-css" href="/css/style.css" type="text/css" media="all">
  <link rel="stylesheet" href="/css/lib.min.css" media="all">
  <link rel="stylesheet" href="/css/font.css" media="all">
  <link rel="stylesheet" href="/css/insight.css" media="all">
  <link rel="stylesheet" href="/css/jquery.fancybox.min.css" media="all">
  <link rel="stylesheet" href="/css/zoom.css" media="all">
  <link rel="stylesheet" type="text/css" href="/css/sharejs.css">
<!--   <link rel="stylesheet" id="saukra_css-css" href="https://2heng.xin/wp-content/cache/autoptimize/css/autoptimize_ad42a61f4c7d4bdd9f91afcff6b5dda5.css
" type="text/css" media="all"> -->
  <script>
  /*Initial Variables*/
  var mashiro_option = new Object();
  var mashiro_global = new Object();
  mashiro_option.NProgressON = true;
  /* 
   * 邮箱信息之类的东西可以填在这里，这些js变量基本都作用于sakura-app.js
   * 这样的设置仅是为了方便在基于PHP开发的主题中设置js变量，既然移植到了Node上，我想或许可以精简这一逻辑吧
   */
  mashiro_option.email_domain = "";
  mashiro_option.email_name = "";
  mashiro_option.cookie_version_control = "";
  mashiro_option.qzone_autocomplete = false;
  mashiro_option.site_name = "CLOSES-clsr";
  mashiro_option.author_name = "-clsr";
  mashiro_option.site_url = "http://closes.gitee.io/";
  mashiro_option.v_appId = "sK63vUmd7V5xKgKMUj6j6ziD-gzGzoHsz";
  mashiro_option.v_appKey = "3u7BeRDq4rfBvBGQcz2zAoxl";
  mashiro_option.mathjax = "0";
  mashiro_option.qq_api_url = "https://api.mashiro.top/qqinfo/"; 
  mashiro_option.qq_avatar_api_url = "https://api.mashiro.top/qqinfo/";

  // mashiro_option.jsdelivr_css_src = "https://cdn.jsdelivr.net/gh/moezx/cdn@3.4.5/css/lib.min.css";
  // mashiro_option.float_player_on = true;

  /*End of Initial Variables*/
  </script>
  <script type="text/javascript">
  var bg = "https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/cover/(1).jpg.webp,https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/cover/(2).jpg.webp,https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/cover/(3).jpg.webp,https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/cover/(4).jpg.webp,https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/cover/(5).jpg.webp,https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/cover/(6).jpg.webp,https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/cover/(7).jpg.webp,https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/cover/(8).jpg.webp".split(",");
  var bgindex = Math.floor(Math.random()*bg.length);
  if (!!window.ActiveXObject || "ActiveXObject" in window) { //is IE?
    alert('朋友，IE浏览器未适配哦~');
  }
  </script>
  <style type="text/css">
  .hljs-ln{border-collapse:collapse}.hljs-ln td{padding:0}.hljs-ln-n:before{content:attr(data-line-number)}
  </style>
  <style type="text/css">.site-top .lower nav{display:block !important;}.author-profile i,.post-like a,.post-share .show-share,.sub-text,.we-info a,span.sitename,.post-more i:hover,#pagination a:hover,.post-content a:hover,.float-content i:hover{color:#FE9600}.feature i,.download,.navigator i:hover,.links ul li:before,.ar-time i,span.ar-circle,.object,.comment .comment-reply-link,.siren-checkbox-radio:checked + .siren-checkbox-radioInput:after{background:#FE9600}::-webkit-scrollbar-thumb{background:#FE9600}.download,.navigator i:hover,.link-title,.links ul li:hover,#pagination a:hover,.comment-respond input[type='submit']:hover{border-color:#FE9600}.entry-content a:hover,.site-info a:hover,.comment h4 a,#comments-navi a.prev,#comments-navi a.next,.comment h4 a:hover,.site-top ul li a:hover,.entry-title a:hover,#archives-temp h3,span.page-numbers.current,.sorry li a:hover,.site-title a:hover,i.iconfont.js-toggle-search.iconsearch:hover,.comment-respond input[type='submit']:hover{color:#FE9600}.comments .comments-main{display:block !important;}.comments .comments-hidden{display:none !important;}background-position:center center;background-attachment:inherit;}
  </style>
</head>
</html>
<body class="page-template page-template-user page-template-page-analytics page-template-userpage-analytics-php page page-id-1297 chinese-font serif isWebKit">
  <div class="scrollbar" id="bar">
  </div>
  <a href="#" class="cd-top faa-float animated"></a>
  <section id="main-container">
    <div class="headertop filter-dot">
  <div id="banner_wave_1"></div>
  <div id="banner_wave_2"></div>
  <figure id="centerbg" class="centerbg">
    <div class="focusinfo no-select">
      <div class="header-tou">
        <a href="http://closes.gitee.io/">
          <img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/logo.png">
        </a>
      </div>
      <div class="header-info">
        <!--<p>你喜欢就甘愿！</p>-->
        <p id="jinrishici-sentence">正在加载今日诗词....</p>
                <script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>
        <div class="top-social_v2">
          <li id="bg-pre">
            <img class="flipx" src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/next-b.svg">
          </li>
          
            
              
                <li>
                  <a href="http://gitee.com/closes" target="_blank" class="social-github" title="github">
                    <img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/github1.png">
                  </a>
                </li>
              
            
              
                <li>
                  <a href="https://music.163.com/#/user?id=549892580" target="_blank" class="social-github" title="wangyiyun">
                    <img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/wangyiyun.png">
                  </a>
                </li>
              
            
              
                <li class="wechat">
                  <a href="/#">
                    <img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/mail.png">
                  </a>
                  <div class="wechatInner">
                    <img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/wechat1.jpg">
                  </div>
                </li>
              
            
              
                <li class="wechat">
                  <a href="/#">
                    <img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/wechat.png">
                  </a>
                  <div class="wechatInner">
                    <img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/wechat1.jpg">
                  </div>
                </li>
              
            
          
          <li id="bg-next">
            <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/next-b.svg">
          </li>
        </div>
      </div>
    </div>
  </figure>
  <div id="video-container" style="">
    <video style="object-fit: fill" id="bgvideo" class="video" video-name="" src="" width="auto" preload="auto">
    </video>
    <div id="video-btn" class="loadvideo videolive">
    </div>
    <div id="video-add">
    </div>
    <div class="video-stu">
    </div>
  </div>
  <div class="headertop-down faa-float animated" onclick="headertop_down()">
    <span>
      <i class="fa fa-chevron-down" aria-hidden="true">
      </i>
    </span>
  </div>
</div>

    <div id="page" class="site wrapper">
      <header class="site-header no-select gizle sabit" role="banner">
  <div class="site-top">
    <div class="site-branding">
      <span class="site-title">
        <span class="logolink moe-mashiro">
          <a href="/">
            <span class="sakurasono">CLOSES</span>
            <span class="shironeko">-clsr</span>
          </a>
        </span>
      </span>
    </div>
    <div class="searchbox search-form-submit">
      <i class="iconfont js-toggle-search iconsearch icon-search">
      </i>
    </div>
    <div id="show-nav" class="showNav mobile-fit">
      <div class="line line1">
      </div>
      <div class="line line2">
      </div>
      <div class="line line3">
      </div>
    </div>
    <div class="lower-cantiner">
      <div class="lower">
        <nav class="mobile-fit-control hide">
          <ul id="menu-new" class="menu">
            
              <li>
                <a href="/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-fort-awesome faa-shake" aria-hidden="true"></i>
                    首页
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/archives">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-archive faa-shake" aria-hidden="true"></i>
                    归档
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/categories/技术/">
                          <i class="fa fa-code" aria-hidden="true"></i>
                          技术
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/生活/">
                          <i class="fa fa-file-text-o" aria-hidden="true"></i>
                          生活
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/资源/">
                          <i class="fa fa-cloud-download" aria-hidden="true"></i>
                          资源
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/随想/">
                          <i class="fa fa-commenting-o" aria-hidden="true"></i>
                          随想
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/转载/">
                          <i class="fa fa-book" aria-hidden="true"></i>
                          转载
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li>
                <a href="javascript:;">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-list-ul faa-vertical" aria-hidden="true"></i>
                    清单
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/tags/悦读/">
                          <i class="fa fa-th-list faa-bounce" aria-hidden="true"></i>
                          书单
                        </a>
                      </li>
                    
                      <li>
                        <a href="/bangumi/">
                          <i class="fa fa-film faa-vertical" aria-hidden="true"></i>
                          番组
                        </a>
                      </li>
                    
                      <li>
                        <a href="/music/">
                          <i class="fa fa-headphones" aria-hidden="true"></i>
                          歌单
                        </a>
                      </li>
                    
                      <li>
                        <a href="/tags/图集/">
                          <i class="fa fa-photo" aria-hidden="true"></i>
                          图集
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li>
                <a href="/tags/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-tag" aria-hidden="true"></i>
                    标签
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/comment/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-pencil-square-o faa-tada" aria-hidden="true"></i>
                    留言板
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/links/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-link faa-shake" aria-hidden="true"></i>
                    友人帐
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/donate/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-heart faa-pulse" aria-hidden="true"></i>
                    赞赏
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-leaf faa-wrench" aria-hidden="true"></i>
                    关于
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/about/">
                          <i class="fa fa-meetup" aria-hidden="true"></i>
                          我？
                        </a>
                      </li>
                    
                      <li>
                        <a href="/theme-sakura/">
                          <i class="fa iconfont icon-sakura" aria-hidden="true"></i>
                          主题
                        </a>
                      </li>
                    
                      <li>
                        <a href="/lab/">
                          <i class="fa fa-cogs" aria-hidden="true"></i>
                          Lab
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
          </ul>
        </nav>
      </div>
    </div>
  </div>
</header>

      <link rel="stylesheet" type="text/css" href="/css/sharejs.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.css">
<div class="pattern-center-blank"></div>

  <div class="pattern-center single-center">
    <!-- 有配图默认渲染第一张 -->
    <div class="pattern-attachment-img lazyload" style="background-image: url(https://cdn.jsdelivr.net/gh/closess/pic-home/img/springcloud-alibaba.png);" src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/loader/orange.progress-bar-stripe-loader.svg" data-src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/springcloud-alibaba.png">
    </div>
    <header class="pattern-header single-header">
      <h1 class="entry-title">
      SpringCloud Alibaba</h1>
      <p class="entry-census">
        <span>
          <a href="http://closes.gitee.io/">
            <img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/logo.png">
          </a>
        </span>
        <span>
          <a href="http://closes.gitee.io/">ChangAn</a>
        </span>
        <span class="bull">
        ·</span>
        2020-11-19<span class="bull">
        ·</span>
      <span id="busuanzi_value_page_pv"></span>次阅读</p>
    </header>
  </div>

<div id="content" class="site-content">
  <div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
      <article id="post-1" class="post-1 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized">
        <div class="toc"></div>
        <!--<div class="toc-entry-content"><!-- 套嵌目录使用（主要为了支援评论）-->
        
        <div class="entry-content">
          <h1 id="Spring-Cloud-Alibaba-微服工具集"><a href="#Spring-Cloud-Alibaba-微服工具集" class="headerlink" title="Spring Cloud Alibaba 微服工具集"></a>Spring Cloud Alibaba 微服工具集</h1><p><strong>版本: 2.2.1</strong> </p>
<h2 id="1-简介"><a href="#1-简介" class="headerlink" title="1.简介"></a>1.简介</h2><p>Spring Cloud Alibaba provides a one-stop solution for distributed application development. It contains all the components required to develop distributed applications, making it easy for you to develop your applications using Spring Cloud.</p>
<p>With Spring Cloud Alibaba, you only need to add some annotations and a small amount of configurations to connect Spring Cloud applications to the distributed solutions of Alibaba, and build a distributed application system with Alibaba middleware.</p>
<pre><code class="markdown"># 0.原文翻译
- https://spring.io/projects/spring-cloud-alibaba
- 阿里云为分布式应用开发提供了一站式解决方案。它包含了开发分布式应用程序所需的所有组件，使您可以轻松地使用springcloud开发应用程序。
- 有了阿里云，你只需要添加一些注解和少量的配置，就可以将Spring云应用连接到阿里的分布式解决方案上，用阿里中间件搭建一个分布式应用系统。
</code></pre>
<h2 id="2-环境搭建"><a href="#2-环境搭建" class="headerlink" title="2.环境搭建"></a>2.环境搭建</h2><pre><code class="markdown"># 0.构建项目并引入依赖
</code></pre>
<pre><code class="xml">&lt;!--定义springcloud版本--&gt;
&lt;properties&gt;
  &lt;spring.cloud.alibaba.version&gt;2.2.1.RELEASE&lt;/spring.cloud.alibaba.version&gt;
&lt;/properties&gt;

&lt;!--全局引入springcloudalibaba下载依赖地址,并不会引入依赖--&gt;
&lt;dependencyManagement&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
      &lt;artifactId&gt;spring-cloud-alibaba-dependencies&lt;/artifactId&gt;
      &lt;version&gt;${spring.cloud.alibaba.version}&lt;/version&gt;
      &lt;type&gt;pom&lt;/type&gt;
      &lt;scope&gt;import&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
&lt;/dependencyManagement&gt;
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200727201703247.png" alt="image-20200727201703247"></p>
<p><img src="Spring Cloud Alibaba.assets/image-20200727201715844.png" alt="image-20200727201715844"></p>
<hr>
<h2 id="3-Nacos"><a href="#3-Nacos" class="headerlink" title="3.Nacos"></a>3.Nacos</h2><h3 id="什么是Nacos-Name-Service-amp-Configurations-Services"><a href="#什么是Nacos-Name-Service-amp-Configurations-Services" class="headerlink" title="什么是Nacos  Name Service &amp; Configurations Services"></a>什么是Nacos  Name Service &amp; Configurations Services</h3><p><img src="Spring Cloud Alibaba.assets/image-20200727202422243.png" alt="image-20200727202422243"></p>
<pre><code class="markdown">- https://nacos.io/zh-cn/index.html
- Nacos 致力于帮助您发现、配置和管理微服务。Nacos 提供了一组简单易用的特性集，帮助您快速实现动态服务发现、服务配置、服务元数据及流量管理。
</code></pre>
<ul>
<li>总结:<strong>Nacos就是微服务架构中服务注册中心以及统一配置中心,用来替换原来的(eureka,consul)以及config组件</strong></li>
</ul>
<h3 id="安装Nacos"><a href="#安装Nacos" class="headerlink" title="安装Nacos"></a>安装Nacos</h3><pre><code class="markdown"># 0.准备环境
- 1.64 bit OS，支持 Linux/Unix/Mac/Windows，推荐选用 Linux/Unix/Mac。
- 2.64 bit JDK 1.8+；下载 &amp; 配置。
- 3.Maven 3.2.x+；下载 &amp; 配置。

# 1.下载nacos [本次课程版本:][1.3.0版本]
- https://github.com/alibaba/nacos/releases 
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200727202936158.png" alt="image-20200727202936158"></p>
<pre><code class="markdown"># 2.解压缩安装包到指定位置
- bin              启动nacos服务的脚本目录
- conf             nacos的配置文件目录
- target         nacos的启动依赖存放目录
- data          nacos启动成功后保存数据的目录
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200727203852405.png" alt="image-20200727203852405"></p>
<pre><code class="markdown"># 3.启动安装服务
- linux/unix/mac启动
    打开终端进入nacos的bin目录执行如下命令 
    ./startup.sh -m standalone

- windows启动
    在 cmd中 
    执行 startup.cmd -m standalone 或者双击startup.cmd运行文件。
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200727204207794.png" alt="image-20200727204207794"></p>
<pre><code class="markdown"># 4.访问nacos的web服务管理界面
- http://localhost:8848/nacos/
- 用户名 和 密码都是nacos
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200727210727986.png" alt="image-20200727210727986"></p>
<h3 id="开发服务注册到nacos"><a href="#开发服务注册到nacos" class="headerlink" title="开发服务注册到nacos"></a>开发服务注册到nacos</h3><pre><code class="markdown"># 0.创建项目并引入依赖
</code></pre>
<pre><code class="xml">&lt;!--引入nacos client的依赖--&gt;
&lt;dependency&gt;
    &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
    &lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-discovery&lt;/artifactId&gt;
&lt;/dependency&gt;
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200727212459690.png" alt="image-20200727212459690"></p>
<pre><code class="markdown"># 1.配置注册地址
</code></pre>
<pre><code class="properties">server.port=8789                                                                                                                 #指定当前服务端口
spring.application.name=nacosclient                                                                            #指定服务名称
spring.cloud.nacos.server-addr=localhost:8848                                                        #指定nacos服务地址
spring.cloud.nacos.discovery.server-addr=${spring.cloud.nacos.server-addr} #指定注册中心地址                            
management.endpoints.web.exposure.include=*                                                          #暴露所有web端点
</code></pre>
<pre><code class="markdown"># 2.加入启动服务注册注解 [注意:][新版本之后这步可以省略不写]
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200727213320726.png" alt="image-20200727213320726"></p>
<pre><code class="markdown"># 3.查看nacos的服务列表
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200727213221604.png" alt="image-20200727213221604"></p>
<h3 id="使用nacos作为配置中心"><a href="#使用nacos作为配置中心" class="headerlink" title="使用nacos作为配置中心"></a>使用nacos作为配置中心</h3><h4 id="1-从nacos获取配置"><a href="#1-从nacos获取配置" class="headerlink" title="1.从nacos获取配置"></a>1.从nacos获取配置</h4><pre><code class="markdown"># 1.创建项目并引入nacons配置中心依赖
</code></pre>
<pre><code class="xml">&lt;!--引入nacos client依赖--&gt;
&lt;dependency&gt;
  &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
  &lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-discovery&lt;/artifactId&gt;
&lt;/dependency&gt;

&lt;!--引入nacos config 依赖--&gt;
&lt;dependency&gt;
  &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
  &lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-config&lt;/artifactId&gt;
&lt;/dependency&gt;
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728203807174.png" alt="image-20200728203807174"></p>
<pre><code class="markdown"># 2.配置配置中心地址
</code></pre>
<pre><code class="properties">spring.cloud.nacos.server-addr=localhost:8848                                # 远程配置中心的地址
spring.cloud.nacos.config.group=DEFAULT_GROUP                                # 读取配置的分组
spring.cloud.nacos.config.file-extension=properties                    # 指定读取文件后缀
spring.application.name=config                                                            # 指定读取文件的前缀
spring.profiles.active=prod                                                                    # 指定读取文件的具体环境
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728211501591.png" alt="image-20200728211501591"></p>
<pre><code class="markdown"># 3.在nacos中创建配置
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728211633327.png" alt="image-20200728211633327"></p>
<p><img src="Spring Cloud Alibaba.assets/image-20200728211924796.png" alt="image-20200728211924796"></p>
<pre><code class="markdown"># 4.编写控制器测试配置读取情况
</code></pre>
<pre><code class="java">@RestController
@Slf4j
public class HelloController {
    //注入配置
    @Value(&quot;${user.name}&quot;)
    private String username;
    @GetMapping(&quot;/hello/config&quot;)
    public String config(){
        log.info(&quot;用户名: [{}]&quot;,username);
        return username;
    }
}
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728212037358.png" alt="image-20200728212037358"></p>
<pre><code class="markdown"># 5.启动项目方式测试配置读取
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728212221271.png" alt="image-20200728212221271"></p>
<p><img src="Spring Cloud Alibaba.assets/image-20200728212249215.png" alt="image-20200728212249215"></p>
<h4 id="2-DataId"><a href="#2-DataId" class="headerlink" title="2. DataId"></a>2. DataId</h4><pre><code class="markdown"># 1.DataId
- 用来读取远程配置中心的中具体配置文件其完整格式如下:
- ${prefix}-${spring.profile.active}.${file-extension}
    a. prefix 默认为 spring.application.name 的值，也可以通过配置项 spring.cloud.nacos.config.prefix来配置。

    b. spring.profile.active 即为当前环境对应的 profile，详情可以参考 Spring Boot文档。 注意：当 spring.profile.active 为空时，对应的连接符 - 也将不存在，dataId 的拼接格式变成 ${prefix}.${file-extension}

    c. file-exetension 为配置内容的数据格式，可以通过配置项 spring.cloud.nacos.config.file-extension 来配置。目前只支持 properties 和 yaml 类型。
</code></pre>
<h4 id="3-实现自动配置刷新"><a href="#3-实现自动配置刷新" class="headerlink" title="3.实现自动配置刷新"></a>3.实现自动配置刷新</h4><pre><code class="markdown"># 1.自动刷新
- 默认情况下nacos已经实现了自动配置刷新功能,如果需要刷新配置直接在控制器中加入@RefreshScope注解即可
</code></pre>
<pre><code class="java">@RestController
@Slf4j
@RefreshScope
public class HelloController {
    //注入配置
    @Value(&quot;${user.name}&quot;)
    private String username;
    @GetMapping(&quot;/hello/config&quot;)
    public String config(){
        log.info(&quot;用户名: [{}]&quot;,username);
        return username;
    }
}
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728215747497.png" alt="image-20200728215747497"></p>
<h4 id="4-命名空间"><a href="#4-命名空间" class="headerlink" title="4.命名空间"></a>4.命名空间</h4><pre><code class="markdown"># 1.命名空间(namespace)
- https://github.com/alibaba/spring-cloud-alibaba/wiki/Nacos-config
- namespace命名空间是nacos针对于企业级开发设计用来针对于不同环境的区分,比如正在企业开发时有测试环境,生产环境,等其他环境,因此为了保证不同环境配置实现隔离,提出了namespace的概念,默认在nacos中存在一个public命名空间所有配置在没有指定命名空间时都在这个命名空间中获取配置,在实际开发时可以针对于不能环境创建不同的namespace空间。默认空间不能删除!
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728220906225.png" alt="image-20200728220906225"></p>
<pre><code class="markdown"># 2.创建其他命名空间
- 每个命名空间都有一个唯一id,这个id是读取配置时指定空间的唯一标识
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728221059584.png" alt="image-20200728221059584"></p>
<p><img src="Spring Cloud Alibaba.assets/image-20200728221139206.png" alt="image-20200728221139206"></p>
<pre><code class="markdown"># 3.在配置列表查看空间
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728221221582.png" alt="image-20200728221221582"></p>
<pre><code class="markdown"># 4.在指定空间下载创建配置文件
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728222410336.png" alt="image-20200728222410336"></p>
<pre><code class="markdown"># 5.项目中使用命名空间指定配置
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728223100749.png" alt="image-20200728223100749"></p>
<pre><code class="markdown"># 6.测试配置
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728223125420.png" alt="image-20200728223125420"></p>
<h4 id="5-配置分组"><a href="#5-配置分组" class="headerlink" title="5.配置分组"></a>5.配置分组</h4><pre><code class="markdown"># 1.配置分组(group)
- 配置分组是对配置集进行分组，通过一个有意义的字符串（如 Buy 或 Trade ）来表示，不同的配置分组下可以有相同的配置集（Data ID）。当您在 Nacos 上创建一个配置时，如果未填写配置分组的名称，则配置分组的名称默认采用 DEFAULT_GROUP 。配置分组的常见场景：可用于区分不同的项目或应用，例如：学生管理系统的配置集可以定义一个group为：STUDENT_GROUP。
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728223745192.png" alt="image-20200728223745192"></p>
<pre><code class="markdown"># 2.创建分组
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728223921240.png" alt="image-20200728223921240"></p>
<p><img src="Spring Cloud Alibaba.assets/image-20200728224034473.png" alt="image-20200728224034473"></p>
<pre><code class="markdown"># 3.读取不同分组的配置
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200728224128019.png" alt="image-20200728224128019"></p>
<hr>
<h2 id="4-sentinel-流量卫兵"><a href="#4-sentinel-流量卫兵" class="headerlink" title="4.sentinel 流量卫兵"></a>4.sentinel 流量卫兵</h2><h3 id="什么是sentinel"><a href="#什么是sentinel" class="headerlink" title="什么是sentinel"></a>什么是sentinel</h3><p><img src="Spring Cloud Alibaba.assets/image-20200730205725897.png" alt="image-20200730205725897"></p>
<p>As microservices become popular, the stability of service calls is becoming increasingly important. <a href="https://github.com/alibaba/Sentinel" target="_blank" rel="noopener">Sentinel</a> takes “flow” as the breakthrough point, and works on multiple fields including flow control, circuit breaking and load protection to protect service reliability.                —[摘自官网]</p>
<pre><code class="markdown"># 0.说明
- https://spring-cloud-alibaba-group.github.io/github-pages/hoxton/en-us/index.html#_how_to_use_sentinel
- https://github.com/alibaba/Sentinel/wiki
- 翻译:随着微服务的普及，服务调用的稳定性变得越来越重要。Sentinel以“流量”为突破口，在流量控制、断路、负载保护等多个领域进行工作，保障服务可靠性。
- 通俗:用来在微服务系统中保护微服务对的作用 如何 服务雪崩 服务熔断  服务降级 就是用来替换hystrix

# 1.特性
- 丰富的应用场景：Sentinel 承接了阿里巴巴近 10 年的双十一大促流量的核心场景，例如秒杀（即突发流量控制在系统容量可以承受的范围）、消息削峰填谷、集群流量控制、实时熔断下游不可用应用等。

- 完备的实时监控：Sentinel 同时提供实时的监控功能。您可以在控制台中看到接入应用的单台机器秒级数据，甚至 500 台以下规模的集群的汇总运行情况。

- 广泛的开源生态：Sentinel 提供开箱即用的与其它开源框架/库的整合模块，例如与 Spring Cloud、Dubbo、gRPC 的整合。您只需要引入相应的依赖并进行简单的配置即可快速地接入 Sentinel。
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730210108995.png" alt="image-20200730210108995"></p>
<h3 id="sentinel使用"><a href="#sentinel使用" class="headerlink" title="sentinel使用"></a>sentinel使用</h3><pre><code class="markdown">- sentinel提供了两个服务组件：
    一个是 sentinel 用来实现微服务系统中服务熔断、降级等功能。这点和hystrix 类似
    一个是 sentinel dashboard 用来监控微服务系统中流量调用等情况。这点和hystrix 类似
</code></pre>
<h4 id="1-sentinel-dashboard的安装"><a href="#1-sentinel-dashboard的安装" class="headerlink" title="1. sentinel dashboard的安装"></a>1. sentinel dashboard的安装</h4><pre><code class="markdown"># 1.下载
- https://github.com/alibaba/Sentinel/releases
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730210627642.png" alt="image-20200730210627642"></p>
<pre><code class="markdown"># 2.启动
- 仪表盘是个jar包可以直接通过java命令启动 如: java -jar 方式运行 默认端口为 8080
- java -Dserver.port=9191 -jar  sentinel-dashboard-1.7.2.jar
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730211707791.png" alt="image-20200730211707791"></p>
<pre><code class="markdown"># 3.访问web界面
- http://localhost:9191/#/login
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730211812235.png" alt="image-20200730211812235"></p>
<pre><code class="markdown"># 4.登录
- 用户名&amp;密码: sentinel
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730212001214.png" alt="image-20200730212001214"></p>
<h4 id="2-sentinel-实时监控服务"><a href="#2-sentinel-实时监控服务" class="headerlink" title="2.sentinel 实时监控服务"></a>2.sentinel 实时监控服务</h4><pre><code class="markdown"># 1.创建项目引入依赖
</code></pre>
<pre><code class="xml">&lt;!--引入nacos client依赖--&gt;
&lt;dependency&gt;
  &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
  &lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-discovery&lt;/artifactId&gt;
&lt;/dependency&gt;

&lt;!--引入sentinel依赖--&gt;
&lt;dependency&gt;
    &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
    &lt;artifactId&gt;spring-cloud-starter-alibaba-sentinel&lt;/artifactId&gt;
&lt;/dependency&gt;
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730213841674.png" alt="image-20200730213841674"></p>
<pre><code class="markdown"># 2.配置
</code></pre>
<pre><code class="properties">server.port=8789
spring.application.name=nacosclient
spring.cloud.nacos.server-addr=localhost:8848
spring.cloud.nacos.discovery.server-addr=${spring.cloud.nacos.server-addr}

spring.cloud.sentinel.enabled=true                                             # 开启sentinel 默认开启
spring.cloud.sentinel.transport.dashboard=localhost:9191 # 连接dashboard
spring.cloud.sentinel.transport.port=8719                                 # 与dashboard通信的端口
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730214440292.png" alt="image-20200730214440292"></p>
<pre><code class="markdown"># 3.启动服务
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730214911616.png" alt="image-20200730214911616"></p>
<pre><code class="markdown"># 4.访问dashboard界面查看服务监控
- 发现界面什么都没有? 
- 默认情况下sentiel为延迟加载,不会在启动之后立即创建服务监控,需要对服务进行调用时才会初始化
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730215003082.png" alt="image-20200730215003082"></p>
<pre><code class="markdown"># 5.开发服务
</code></pre>
<pre><code class="java">@RestController
@Slf4j
public class SentinelController {
    @GetMapping(&quot;/sentinel/test&quot;)
    public String test(){
        log.info(&quot;sentinel test&quot;);
        return &quot;sentinel test &quot;;
    }

    @GetMapping(&quot;/sentinel/test1&quot;)
    public String test1(){
        log.info(&quot;sentinel test1&quot;);
        return &quot;sentinel test1 &quot;;
    }
}
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730215202043.png" alt="image-20200730215202043"></p>
<pre><code class="markdown"># 6.启动进行调用
- http://localhost:8789/sentinel/test
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730215227292.png" alt="image-20200730215227292"></p>
<pre><code class="markdown"># 7.查看监控界面
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730215420417.png" alt="image-20200730215420417"></p>
<h4 id="3-sentinel-流量控制"><a href="#3-sentinel-流量控制" class="headerlink" title="3.sentinel 流量控制"></a>3.sentinel 流量控制</h4><pre><code class="markdown"># 0.说明
- 流量控制（flow control），其原理是监控应用流量的 QPS 或并发线程数等指标，当达到指定的阈值时对流量进行控制，以避免被瞬时的流量高峰冲垮，从而保障应用的高可用性。

- 同一个资源可以创建多条限流规则。FlowSlot 会对该资源的所有限流规则依次遍历，直到有规则触发限流或者所有规则遍历完毕。

- 一条限流规则主要由下面几个因素组成，我们可以组合这些元素来实现不同的限流效果：
    resource：资源名，即限流规则的作用对象
    count: 限流阈值
    grade: 限流阈值类型（QPS 或并发线程数）
    limitApp: 流控针对的调用来源，若为 default 则不区分调用来源
    strategy: 调用关系限流策略
    controlBehavior: 流量控制效果（直接拒绝、Warm Up、匀速排队）

- 流量控制主要有两种统计类型，一种是统计并发线程数，另外一种则是统计 QPS
- 更多细节参见官网:https://github.com/alibaba/Sentinel/wiki/%E6%B5%81%E9%87%8F%E6%8E%A7%E5%88%B6
</code></pre>
<h6 id="QPS限流"><a href="#QPS限流" class="headerlink" title="QPS限流"></a>QPS限流</h6><pre><code class="markdown"># 1.配置QPS流量控制
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730220822573.png" alt="image-20200730220822573"></p>
<p><img src="Spring Cloud Alibaba.assets/image-20200730220846876.png" alt="image-20200730220846876"></p>
<pre><code class="markdown"># 2.测试
- 每秒只能最大接收1个请求,超过1个报错
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730220950595.png" alt="image-20200730220950595"></p>
<h6 id="线程数限流"><a href="#线程数限流" class="headerlink" title="线程数限流"></a>线程数限流</h6><pre><code class="markdown"># 1.配置线程数限流
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730223510370.png" alt="image-20200730223510370"></p>
<pre><code class="markdown"># 2.访问测试
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200730224844222.png" alt="image-20200730224844222"></p>
<h6 id="流控模式"><a href="#流控模式" class="headerlink" title="流控模式"></a>流控模式</h6><pre><code class="markdown"># 1.说明
- 直接:标识流量控制规则到达阈值直接触发流量控制
- 关联: 当两个资源之间具有资源争抢或者依赖关系的时候，这两个资源便具有了关联。比如对数据库同一个字段的读操作和写操作存在争抢，读的速度过高会影响写得速度，写的速度过高会影响读的速度。如果放任读写操作争抢资源，则争抢本身带来的开销会降低整体的吞吐量。可使用关联限流来避免具有关联关系的资源之间过度的争抢，举例来说，read_db 和 write_db 这两个资源分别代表数据库读写，我们可以给 read_db 设置限流规则来达到写优先的目的：设置 strategy 为 RuleConstant.STRATEGY_RELATE 同时设置 refResource 为 write_db。这样当写库操作过于频繁时，读数据的请求会被限流。
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200801195347534.png" alt="image-20200801195347534"></p>
<pre><code class="markdown">- 链路限流: https://github.com/alibaba/Sentinel/wiki/%E6%B5%81%E9%87%8F%E6%8E%A7%E5%88%B6
</code></pre>
<h6 id="流控效果"><a href="#流控效果" class="headerlink" title="流控效果"></a>流控效果</h6><pre><code class="markdown">- 直接拒绝:（RuleConstant.CONTROL_BEHAVIOR_DEFAULT）方式是默认的流量控制方式，当QPS超过任意规则的阈值后，新的请求就会被立即拒绝，拒绝方式为抛出FlowException。

- Warm Up:（RuleConstant.CONTROL_BEHAVIOR_WARM_UP）方式，即预热/冷启动方式。当系统长期处于低水位的情况下，当流量突然增加时，直接把系统拉升到高水位可能瞬间把系统压垮。通过&quot;冷启动&quot;，让通过的流量缓慢增加，在一定时间内逐渐增加到阈值上限，给冷系统一个预热的时间，避免冷系统被压垮。
    更多:https://github.com/alibaba/Sentinel/wiki/%E9%99%90%E6%B5%81---%E5%86%B7%E5%90%AF%E5%8A%A8


- 匀速排队:(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER）方式会严格控制请求通过的间隔时间，也即是让请求以均匀的速度通过，对应的是漏桶算法。 只能对请求进行排队等待
    更多:https://github.com/alibaba/Sentinel/wiki/%E6%B5%81%E9%87%8F%E6%8E%A7%E5%88%B6-%E5%8C%80%E9%80%9F%E6%8E%92%E9%98%9F%E6%A8%A1%E5%BC%8F
</code></pre>
<hr>
<h4 id="4-熔断降级"><a href="#4-熔断降级" class="headerlink" title="4.熔断降级"></a>4.熔断降级</h4><pre><code class="markdown"># 0.说明
- https://github.com/alibaba/Sentinel/wiki/%E7%86%94%E6%96%AD%E9%99%8D%E7%BA%A7
- 除了流量控制以外，对调用链路中不稳定的资源进行熔断降级也是保障高可用的重要措施之一。由于调用关系的复杂性，如果调用链路中的某个资源不稳定，最终会导致请求发生堆积。Sentinel **熔断降级**会在调用链路中某个资源出现不稳定状态时（例如调用超时或异常比例升高），对这个资源的调用进行限制，让请求快速失败，避免影响到其它的资源而导致级联错误。当资源被降级后，在接下来的降级时间窗口之内，对该资源的调用都自动熔断（默认行为是抛出 `DegradeException`）。
</code></pre>
<h6 id="降级策略"><a href="#降级策略" class="headerlink" title="降级策略"></a>降级策略</h6><ul>
<li>平均响应时间 (DEGRADE_GRADE_RT)：当 1s 内持续进入 N 个请求，对应时刻的平均响应时间（秒级）均超过阈值（count，以 ms 为单位），那么在接下的时间窗口（DegradeRule 中的 timeWindow，以 s 为单位）之内，对这个方法的调用都会自动地熔断（抛出 DegradeException）。注意 Sentinel 默认统计的 RT 上限是 4900 ms，超出此阈值的都会算作 4900 ms，若需要变更此上限可以通过启动配置项 -Dcsp.sentinel.statistic.max.rt=xxx 来配置。</li>
</ul>
<p><img src="Spring Cloud Alibaba.assets/image-20200802142932522.png" alt="image-20200802142932522"></p>
<ul>
<li>异常比例 (DEGRADE_GRADE_EXCEPTION_RATIO)：当资源的每秒请求量 &gt;= N（可配置），并且每秒异常总数占通过量的比值超过阈值（DegradeRule 中的 count）之后，资源进入降级状态，即在接下的时间窗口（DegradeRule 中的 timeWindow，以 s 为单位）之内，对这个方法的调用都会自动地返回。异常比率的阈值范围是 [0.0, 1.0]，代表 0% - 100%。</li>
</ul>
<p><img src="Spring Cloud Alibaba.assets/image-20200802143052470.png" alt="image-20200802143052470"></p>
<ul>
<li>异常数 (DEGRADE_GRADE_EXCEPTION_COUNT)：当资源近 1 分钟的异常数目超过阈值之后会进行熔断。注意由于统计时间窗口是分钟级别的，若 timeWindow 小于 60s，则结束熔断状态后仍可能再进入熔断状态。</li>
</ul>
<p><img src="Spring Cloud Alibaba.assets/image-20200802143314524.png" alt="image-20200802143314524"></p>
<h4 id="5-SentinelResource注解"><a href="#5-SentinelResource注解" class="headerlink" title="5.SentinelResource注解"></a>5.SentinelResource注解</h4><pre><code class="markdown"># 0.说明
- https://github.com/alibaba/Sentinel/wiki/%E6%B3%A8%E8%A7%A3%E6%94%AF%E6%8C%81
</code></pre>
<p><img src="Spring Cloud Alibaba.assets/image-20200802150527319.png" alt="image-20200802150527319"></p>
<pre><code class="java"> @GetMapping(&quot;/sentinel/test1&quot;)
    @SentinelResource(value = &quot;aa&quot;,blockHandler = &quot;fallBack&quot;,fallback = &quot;fall&quot;)
    public String test1(int id){
        log.info(&quot;sentinel test1&quot;);
        if(id&lt;0)        
            throw new RuntimeException(&quot;非法参数!!!&quot;);
        }
        return &quot;sentinel test1 :&quot;+id;
    }
        //降级异常处理
    public String fallBack(int id,BlockException e){
            if(e instanceof FlowException){
                return &quot;当前服务已被流控! &quot;+e.getClass().getCanonicalName();
            }
            return &quot;当前服务已被降级处理! &quot;+e.getClass().getCanonicalName();
    }
        //异常处理
    public String fall(int id){
        return &quot;当前服务已不可用!&quot;;
    }
</code></pre>
<h2 id="5-整合环境公共依赖"><a href="#5-整合环境公共依赖" class="headerlink" title="5.整合环境公共依赖"></a>5.整合环境公共依赖</h2><p><strong>spring boot 2.2+</strong></p>
<p><strong>springcloud Hoxton</strong></p>
<p><strong>springcloud alibaba 2.2.1+</strong></p>
<pre><code class="markdown"># 0.构建项目并引入依赖
</code></pre>
<pre><code class="xml">
&lt;properties&gt;
  &lt;java.version&gt;1.8&lt;/java.version&gt;
  &lt;spring-cloud.version&gt;Hoxton.SR6&lt;/spring-cloud.version&gt;
  &lt;spring.cloud.alibaba.version&gt;2.2.1.RELEASE&lt;/spring.cloud.alibaba.version&gt;
&lt;/properties&gt;

&lt;dependencyManagement&gt;
  &lt;dependencies&gt;
    &lt;!--引入springcloud alibaba--&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
      &lt;artifactId&gt;spring-cloud-alibaba-dependencies&lt;/artifactId&gt;
      &lt;version&gt;${spring.cloud.alibaba.version}&lt;/version&gt;
      &lt;type&gt;pom&lt;/type&gt;
      &lt;scope&gt;import&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;!--引入springcloud--&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
      &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
      &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
      &lt;type&gt;pom&lt;/type&gt;
      &lt;scope&gt;import&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
&lt;/dependencyManagement&gt;
</code></pre>
<hr>

        </div>
        <!-- .entry-content -->
        <div class="single-reward">
          <div class="reward-open">赏
            <div class="reward-main">
              <ul class="reward-row">
                <li class="alipay-code"><img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/ailipay.jpg"></li>
                <li class="wechat-code"><img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/weixinpay.png"></li>
              </ul>
            </div>
          </div>
        </div>
        <div style="text-align:center; width: 100%" class="social-share share-mobile" data-disabled="diandian, tencent"></div>
        <footer class="post-footer">
          <div class="post-lincenses"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank" rel="nofollow"><i class="fa fa-creative-commons" aria-hidden="true"></i> 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议</a></div>
          <div class="post-tags">
          </div>
          <div class="post-share">
            <div class="social-share sharehidden share-component"></div>
            <i class="iconfont show-share icon-forward"></i>
          </div>
        </footer><!-- .entry-footer -->
      </article>
      <!-- #post-## -->
      <div class="toc" style="background: none;"></div>
      <section class="post-squares nextprev">
        
          
            <div class="post-nepre half previous">
          
            <a href="/2020/11/20/SSM网上商城介绍/" rel="prev">
              <div class="background">
                <img class="lazyload" src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/loader/orange.progress-bar-stripe-loader.svg" data-src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/image-20201120171526993.png" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;" onerror="imgError(this,3)" src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/image-20201120171526993.png">
              </div>
              <span class="label">
              Previous Post</span>
              <div class="info">
                <h3>
                SSM网上商城介绍</h3>
                <hr>
              </div>
            </a>
          </div>
        
        
          
            <div class="post-nepre half next">
          
            <a href="/2020/11/18/hello-world/" rel="next">
              <div class="background">
                <img class="lazyload" src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/loader/orange.progress-bar-stripe-loader.svg" data-src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/helloworld.png" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;" onerror="imgError(this,3)" src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/helloworld.png">
              </div>
              <span class="label">
              Next Post</span>
              <div class="info">
                <h3>
                Hello World</h3>
                <hr>
              </div>
            </a>
          </div>
        
      </section>
      
<div id="vcomments"></div>
<script>
  window.onload = function(){
      var valine = new Valine();
      valine.init({
        el: '#vcomments',
        appId: "sK63vUmd7V5xKgKMUj6j6ziD-gzGzoHsz",
        appKey: "3u7BeRDq4rfBvBGQcz2zAoxl",
        path: window.location.pathname,
        placeholder: "你是我一生只会遇见一次的惊喜 ..."
      })
  }
</script>

      <section class="author-profile">
        <div class="info" itemprop="author" itemscope="" itemtype="https://schema.org/Person">
          <a href="http://closes.gitee.io/" class="profile gravatar"><img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/logo.png" itemprop="image" alt="ChangAn" height="70" width="70"></a>
          <div class="meta">
            <span class="title">Author</span>
            <h3 itemprop="name">
            <a href="http://closes.gitee.io/" itemprop="url" rel="author">ChangAn</a>
            </h3>
          </div>
        </div>
        <hr>
        <p><i class="iconfont icon-write"></i>一个好奇的人</p>
      </section>
    </main><!-- #main -->
  </div><!-- #primary -->
</div>



    </div>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="请输入关键词..."/>
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            // PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
    <!-- <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 wmw<br>
      powered_by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer> -->
<footer id="colophon" class="site-footer" role="contentinfo">
  <div class="site-info">
    <div class="footertext">
      <div class="img-preload">
        <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/wordpress-rotating-ball-o.svg">
        <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/disqus-preloader.svg">
      </div>
      <p style="color: #666666;">&copy 2020</p>
    </div>
    <div class="footer-device">
    <p style="font-family: 'Ubuntu', sans-serif;">
        <span style="color: #b9b9b9;">Theme <a href="https://github.com/honjun/hexo-theme-sakura" target="_blank" style="color: #b9b9b9;;text-decoration: underline dotted rgba(0, 0, 0, .1);">Sakura</a> <i class="iconfont icon-sakura rotating" style="color: #ffc0cb;display:inline-block"></i> by <a href="https://2heng.xin/" target="_blank" style="color: #b9b9b9;;text-decoration: underline dotted rgba(0, 0, 0, .1);">Mashiro</a>&<a href="https://www.hojun.cn/" target="_blank" style="color: #b9b9b9;;text-decoration: underline dotted rgba(0, 0, 0, .1);">Hojun</a>, Powered by Hexo, Hosted by Coding Pages</a>
        </span>
      </p>
    </div>
  </div><!-- .site-info -->
</footer>
<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span><script>
  var now = new Date();
  function createtime() {
    var grt= new Date("11/18/2020 13:14:00");//此处修改你的建站时间或者网站上线时间
    now.setTime(now.getTime()+250);
    days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days);
    hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours);
    if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
    mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;}
    seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
    snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;}
    document.getElementById("timeDate").innerHTML = "本站已安全运行 "+dnum+" 天 ";
    document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
  }
  setInterval("createtime()",250);</script>



<!-- <script src="/js/tocbot.js"></script> -->
<script type="text/javascript" src="/js/lib.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script type="text/javascript" src="/js/InsightSearch.js"></script>
<script type="text/javascript" src="/js/jquery.fancybox.min.js"></script>
<script type="text/javascript" src="/js/zoom.min.js"></script>
<script type="text/javascript" src="/js/sakura-app.js"></script>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='//unpkg.com/valine@1.3.4/dist/Valine.min.js'></script>
<script src="/js/botui.js"></script>
<!-- 不蒜子 网页计数器 -->
<script src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.min.js"></script> -->
<script type="text/javascript">
/* <![CDATA[ */
if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
  var Poi = {"pjax":"1","movies":{"url": "https://cdn.jsdelivr.net/gh/honjun/hojun@1.2","name":"Unbroken.mp4","live":"close"},"windowheight":"fixed","codelamp":"close","ajaxurl":"","order":"asc","formpostion":"bottom"};
} else {
  var Poi = {"pjax":"1","movies":{"url": "https://cdn.jsdelivr.net/gh/honjun/hojun@1.2","name":"Unbroken.mp4","live":"open"},"windowheight":"auto","codelamp":"close","ajaxurl":"","order":"asc","formpostion":"bottom"};
}
/* ]]> */

</script>
<script>
$(document).ready(function() {
  if ($(".toc").length > 0 && document.body.clientWidth > 1200) {
    if ($(".pattern-center").length > 0) { //有图的情况
      tocbot.init({
          // Where to render the table of contents.
          tocSelector: '.toc', // 放置目录的容器
          // Where to grab the headings to build the table of contents.
          contentSelector: '.entry-content', // 正文内容所在
          // Which headings to grab inside of the contentSelector element.
          scrollSmooth: true,
          headingSelector: 'h1, h2, h3, h4, h5', // 需要索引的标题级别
          headingsOffset: -400,
          scrollSmoothOffset: -85
      });
    } else {
      tocbot.init({
          // Where to render the table of contents.
          tocSelector: '.toc', // 放置目录的容器
          // Where to grab the headings to build the table of contents.
          contentSelector: '.entry-content', // 正文内容所在
          // Which headings to grab inside of the contentSelector element.
          scrollSmooth: true,
          headingSelector: 'h1, h2, h3, h4, h5', // 需要索引的标题级别
          headingsOffset: -85,
          scrollSmoothOffset: -85
      });
    }
    var offsetTop = $('.toc').offset().top - 95;
    window.onscroll = function() {
      var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
      if (scrollTop >= offsetTop) {
        $('.toc').addClass('toc-fixed');
      } else {
        $('.toc').removeClass('toc-fixed');
      }
    }
  }
});
</script>
<div id="binft"></div>
  <script>
    var binft = function (r) {
      function t() {
        return b[Math.floor(Math.random() * b.length)]
      }
      function e() {
        return String.fromCharCode(94 * Math.random() + 33)
      }
      function n(r) {
        for (var n = document.createDocumentFragment(), i = 0; r > i; i++) {
          var l = document.createElement("span");
          l.textContent = e(), l.style.color = t(), n.appendChild(l)
        }
        return n
      }
      function i() {
        var t = o[c.skillI];
        c.step ? c.step-- : (c.step = g, c.prefixP < l.length ? (c.prefixP >= 0 && (c.text += l[c.prefixP]), c.prefixP++) : "forward" === c.direction ? c.skillP < t.length ? (c.text += t[c.skillP], c.skillP++) : c.delay ? c.delay-- : (c.direction = "backward", c.delay = a) : c.skillP > 0 ? (c.text = c.text.slice(0, -1), c.skillP--) : (c.skillI = (c.skillI + 1) % o.length, c.direction = "forward")), r.textContent = c.text, r.appendChild(n(c.prefixP < l.length ? Math.min(s, s + c.prefixP) : Math.min(s, t.length - c.skillP))), setTimeout(i, d)
      }
      var l = "",
      o = ["青青陵上柏，磊磊涧中石。", "人生天地间，忽如远行客。","斗酒相娱乐，聊厚不为薄。", "驱车策驽马，游戏宛与洛。","洛中何郁郁，冠带自相索。","长衢罗夹巷，王侯多第宅。","两宫遥相望，双阙百余尺。","极宴娱心意，戚戚何所迫？"].map(function (r) {
      return r + ""
      }),
      a = 2,
      g = 1,
      s = 5,
      d = 75,
      b = ["rgb(110,64,170)", "rgb(150,61,179)", "rgb(191,60,175)", "rgb(228,65,157)", "rgb(254,75,131)", "rgb(255,94,99)", "rgb(255,120,71)", "rgb(251,150,51)", "rgb(226,183,47)", "rgb(198,214,60)", "rgb(175,240,91)", "rgb(127,246,88)", "rgb(82,246,103)", "rgb(48,239,130)", "rgb(29,223,163)", "rgb(26,199,194)", "rgb(35,171,216)", "rgb(54,140,225)", "rgb(76,110,219)", "rgb(96,84,200)"],
      c = {
        text: "",
        prefixP: -s,
        skillI: 0,
        skillP: 0,
        direction: "forward",
        delay: a,
        step: g
      };
      i()
      };
      binft(document.getElementById('binft'));
  </script>



    <div class="openNav no-select" style="height: 50px;">
      <div class="iconflat no-select" style="width: 50px; height: 50px;">
        <div class="icon"></div>
      </div>
      <div class="site-branding search-form-submit">
        <i class="iconfont js-toggle-search iconsearch icon-search"></i>
      </div>
    </div>
  </section>
  <div id="mo-nav" class="">
  <div class="m-avatar">
    <img src="https://cdn.jsdelivr.net/gh/closess/pic-home/img/logo.png">
  </div>
  <p style="text-align: center; color: #333; font-weight: 900; font-family: 'Ubuntu', sans-serif; letter-spacing: 1.5px">CLOSES-clsr</p>
  <p style="text-align: center; word-spacing: 20px;">
    
      
        <a href="http://github.com/closess" class="fa fa-github" target="_blank" style="color: #333; margin-left:20px"></a>
      
        <a href="http://weibo.com/mashirozx?is_all=1" class="fa fa-weibo" target="_blank" style="color: #dd4b39; margin-left:20px"></a>
      
        <a href="https://wpa.qq.com/msgrd?v=3&uin=954655431&site=qq&menu=yes" class="fa fa-qq" target="_blank" style="color: #25c6fe; margin-left:20px"></a>
      
    
  </p>
  <ul id="menu-new-1" class="menu">
    
      <li>
        <a href="/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-fort-awesome faa-shake" aria-hidden="true"></i>
            首页
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/archives">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-archive faa-shake" aria-hidden="true"></i>
            归档
          </span>
        </a>
        
          <ul class="sub-menu">
            
              <li>
                <a href="/categories/技术/">
                  <i class="fa fa-code" aria-hidden="true"></i>
                  技术
                </a>
              </li>
            
              <li>
                <a href="/categories/生活/">
                  <i class="fa fa-file-text-o" aria-hidden="true"></i>
                  生活
                </a>
              </li>
            
              <li>
                <a href="/categories/资源/">
                  <i class="fa fa-cloud-download" aria-hidden="true"></i>
                  资源
                </a>
              </li>
            
              <li>
                <a href="/categories/随想/">
                  <i class="fa fa-commenting-o" aria-hidden="true"></i>
                  随想
                </a>
              </li>
            
              <li>
                <a href="/categories/转载/">
                  <i class="fa fa-book" aria-hidden="true"></i>
                  转载
                </a>
              </li>
            
          </ul>
        
      </li>
    
      <li>
        <a href="javascript:;">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-list-ul faa-vertical" aria-hidden="true"></i>
            清单
          </span>
        </a>
        
          <ul class="sub-menu">
            
              <li>
                <a href="/tags/悦读/">
                  <i class="fa fa-th-list faa-bounce" aria-hidden="true"></i>
                  书单
                </a>
              </li>
            
              <li>
                <a href="/bangumi/">
                  <i class="fa fa-film faa-vertical" aria-hidden="true"></i>
                  番组
                </a>
              </li>
            
              <li>
                <a href="/music/">
                  <i class="fa fa-headphones" aria-hidden="true"></i>
                  歌单
                </a>
              </li>
            
              <li>
                <a href="/tags/图集/">
                  <i class="fa fa-photo" aria-hidden="true"></i>
                  图集
                </a>
              </li>
            
          </ul>
        
      </li>
    
      <li>
        <a href="/tags/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-tag" aria-hidden="true"></i>
            标签
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/comment/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-pencil-square-o faa-tada" aria-hidden="true"></i>
            留言板
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/links/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-link faa-shake" aria-hidden="true"></i>
            友人帐
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/donate/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-heart faa-pulse" aria-hidden="true"></i>
            赞赏
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-leaf faa-wrench" aria-hidden="true"></i>
            关于
          </span>
        </a>
        
          <ul class="sub-menu">
            
              <li>
                <a href="/about/">
                  <i class="fa fa-meetup" aria-hidden="true"></i>
                  我？
                </a>
              </li>
            
              <li>
                <a href="/theme-sakura/">
                  <i class="fa iconfont icon-sakura" aria-hidden="true"></i>
                  主题
                </a>
              </li>
            
              <li>
                <a href="/lab/">
                  <i class="fa fa-cogs" aria-hidden="true"></i>
                  Lab
                </a>
              </li>
            
          </ul>
        
      </li>
    
  </ul>
  <p style="text-align: center; font-size: 13px; color: #b9b9b9;">&copy 2019 hexo-sakura</p>
</div>
<button onclick="topFunction()" class="mobile-cd-top" id="moblieGoTop" title="Go to top" style="display: none;"><i class="fa fa-chevron-up" aria-hidden="true"></i></button>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">
<script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
<!-- require MetingJS -->
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>
<style>
  .aplayer .aplayer-lrc {
    height: 35px;
  }
  .aplayer .aplayer-lrc p{
    font-size: 16px;
    font-weight: 700;
    line-height: 18px !important;
  }
  .aplayer .aplayer-lrc p.aplayer-lrc-current{
    color: #FF1493;
  }
  .aplayer.aplayer-narrow .aplayer-body{
    left: -66px !important;
  }
  .aplayer.aplayer-fixed .aplayer-lrc {
    display: none;
  }
  .aplayer .aplayer-lrc.aplayer-lrc-hide {
      display:none !important;
  }
  .aplayer.aplayer-fixed .lrc-show {
    display: block;
    background: rgba(255, 255, 255, 0.8);
  }
</style>
<meting-js

    id="824097036"

    server="netease"

    type="playlist"

    fixed="true"

    autoplay="false"

    loop="all"

    order="random"

    preload="auto"

    volume="0.7"

    mutex="true"

</meting-js>
<script>
  $(function(){
    $('body').on('click', '.aplayer', function(){
      if($('.aplayer-button').hasClass('aplayer-play')) {
        $('.aplayer-lrc').removeClass('lrc-show');
      } else {
        $('.aplayer-lrc').addClass('lrc-show');
      }
    })
  });
</script>
  <script src="https://cdn.jsdelivr.net/gh/wallleap/cdn/js/xuehua.js"></script>
  <script src="https://cdn.jsdelivr.net/gh/wallleap/cdn/js/piao.js"></script>
  <!--樱花-->
  <!--<script src="https://cdn.jsdelivr.net/gh/wallleap/cdn/js/sakura.js"></script>-->
  <!--雪花-->
  <script src="https://cdn.jsdelivr.net/gh/wallleap/cdn/js/xuehuapiaoluo.js"></script>或者<script src="https://cdn.jsdelivr.net/gh/wallleap/cdn/js/snow.js"></script>
  <!--为了阻止某些使用F12、Ctrl+Alt+I调用开发者选项的用户
  还有禁用了鼠标右键，可以开启禁用鼠标左键拖动选择文字-->
<!--<script src="https://cdn.jsdelivr.net/gh/wallleap/cdn/js/noSomeKey.js"></script>-->
<!--画板娘-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"> <!-- 这条在sakura中已有，可不添加 --><script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>
<!--加入懒加载-->
<script src="//instant.page/3.0.0" type="module" defer integrity="sha384-OeDn4XE77tdHo8pGtE1apMPmAipjoxUQ++eeJa6EtJCfHlvijigWiJpD7VDPWXV1"></script>
</body>
</html>
